#ifndef X264VIDEOENCODER_H
#define X264VIDEOENCODER_H

#include "stdint.h"
#include "x264.h"
#include <stdio.h>

#define LOG_INFO 1

static const int MAX_PS_SIZE = 64;

class CX264VideoEncoder
{
public:
	CX264VideoEncoder();
	~CX264VideoEncoder();

public:
	bool Open(int aWidth, int aHeight, int aAnnexB = 0,
		uint8_t * aSPSBuffer = NULL, int * aSPSLen = NULL, 
		uint8_t * aPPSBuffer = NULL, int * aPPSLen = NULL);
	bool Encode(uint8_t * inBuffer, uint8_t * outBuffer, int * outLen, int * frameType, int bAnnexB = 0);
	void Close();

	//void SetResolution(int aWidth, int aHeight);
	bool GetSPS(uint8_t * aSPSBuffer, int * aSPSLen, int aAnnexB = 0);
	bool GetPPS(uint8_t * aPPSBuffer, int * aPPSLen, int aAnnexB = 0);
	int GetFrame() { return m_frames; };

private:
	void LoadConfig(const char * aFile);
	void CustomizeParam();
	void UpdatePS();

private:
	x264_t * m_x264;
	x264_param_t * m_param;
	x264_picture_t * m_pic;

	uint8_t m_spsBuffer[MAX_PS_SIZE];
	uint8_t m_ppsBuffer[MAX_PS_SIZE];
	int m_spsLen;
	int m_ppsLen;

	int m_frames;

#if LOG_INFO
	FILE * m_logFile;
	double m_encodedTime;
#endif

};

#endif
